package com.jinmdz.fmis.dao.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

import java.util.ArrayList;

/**
 * 抬尸工Provider
 *
 * @author LiCongLu
 * @date 2020-02-13 15:34
 */
public class TransportTaskPorterProvider {
    /**
     * 批量逻辑删除抬尸工
     *
     * @param
     * @return
     * @author LiCongLu
     * @date 2020-02-13 15:35
     */
    public String deletedForTransportTaskPorterByUserIds(@Param("transportTaskId") Integer transportTaskId, @Param("modifiedUserId") Integer modifiedUserId, @Param("userIds") ArrayList<Integer> userIds) {
        return new SQL() {
            {
                UPDATE(" transport_task_porter ");

                SET(" deleted = 1 ");
                SET(" modified_user_id = #{modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");

                WHERE(" transport_task_id = #{transportTaskId} ");
                WHERE(" unmodified = 0 and deleted = 0");
                // 拼接抬尸工主键
                String idString = StringUtils.arrayToDelimitedString(userIds.toArray(new Integer[]{}), ",");
                WHERE("  system_user_id in (" + idString + ")");
            }
        }.toString();
    }
}
